//axios 的请求封装
import Vue from 'vue';
import axios from 'axios';

const $axios = axios.create({
  baseURL: '/api',
  timeout: 5000
})
$axios.defaults.headers.post['Content-Type'] = 'application/json'

$axios.interceptors.request.use(
  config => {
    // do something before request is sent

    // if (store.getters.token) {
    //   // let each request carry token
    //   // ['X-Token'] is a custom headers key
    //   // please modify it according to the actual situation
    //   config.headers['X-Token'] = getToken()
    // }
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

export default $axios;